package com.some;

public class XiaPi_2 {
    /**
     * Note: 类名、方法名、参数名已经指定，请勿修改
     *
     * @param s string字符串
     * @return int整型
     */
    public int MinOperations(String s) {
        // write code here
        int tmp = 0, tmp2 = 0;
        char[] chars = s.toCharArray();
        chars[0] = 'A';
        tmp = getRes(chars);
        chars[0] = 'B';
        tmp2 = getRes(chars);
        return Math.min(tmp, tmp2);
    }

    private int getRes(char[] chars) {
        int tmp = 0;
        char charI = chars[0];
        char charJ = chars[0] == 'A' ? 'B' : 'A';
        for (int i = 0, j = 1; i < chars.length - 1 || j < chars.length - 1; i += 2, j += 2) {
            if (i < chars.length - 1 && chars[i] != charI) {
                tmp++;
            }
            if (j < chars.length - 1 && chars[j] != charJ) {
                tmp++;
            }
        }
        return tmp;
    }

    public static void main(String[] args) {

    }
}
